package cn.secby.wms.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class ReadDataUtil {
    public Instance getInstance(String path) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new FileReader(path));
        String input = null;
        Instance instance = new Instance();
        List<Square> squareList = new ArrayList<>();
        boolean isFirstLine = true;
        while ((input=bufferedReader.readLine())!=null){
            String[] split = input.split(" ");
            if(isFirstLine){
                instance.setL(Double.parseDouble(split[0]));
                instance.setW(Double.parseDouble(split[1]));
                if(split[2].equals("1")){
                    instance.setRotateEnable(true);
                }else{
                    instance.setRotateEnable(false);
                }
                isFirstLine = false;
            }else{
                squareList.add(new Square(UUID.randomUUID().toString(),Double.parseDouble(split[0]),Double.parseDouble(split[1])));
            }
        }
        instance.setSquareList(squareList);
        return instance;
    }
}